<template>
	<view class="more-detail padding-15">
		<view class="align_center">
			<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange" fields="month">
				<view class="uni-input">{{date1}}</view>
			</picker>
			<uni-icons type="arrowdown" size="15" class="close"></uni-icons>

		</view>
		<view v-if="total">
			<view v-for="(item,index) in list" class="flex sign">
				<image src="../../static/img/pay_out.png" mode="" v-if="item.num<0" style="width: 52rpx;height: 52rpx;margin-left:5rpx;"></image>
				<image src="../../static/img/pay_in.png" mode="" v-else></image>
				<view class="flex-left-right flex-full" style="border-bottom:1px solid #eee;padding: 30rpx 0;">
					<view>
						<view>{{item.typedata}}</view>
						<view class="fs-12 gray_font">{{item.signtime?item.signtime:$fomartDate(item.createtime).substring(0,10)}}</view>
					</view>
					<text v-if="item.num<0" class="bold">{{item.num}}</text>
					<text v-else class="bold red-font"> +{{item.num}}</text>
				</view>
			</view>
		</view>
		<view v-else class="bitmap" style="padding-top: 100rpx;">
			<image :src="none" mode="widthFix"></image>
			<view class="fs-13 gray_font">暂时没有积分明细哦</view>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				date: currentDate,
				list:[],
				month:'',
				date1:'',
				total:0,
				none:''
			}
		},
		onLoad() {
			this.none=this.$imgUrl+'assets/img/none_jf.png';
			this.getList();
			this.getNow();
		},
		computed: {
			startDate(){
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		methods: {
			getNow(){
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
			
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				
				this.date1= `${year}年${month}月`;
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year-2 ;
				} else if (type === 'end') {
					year = year ;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				// this.date=`${year}年${month}月`;
				// this.month=`${year}-${month}`;
				return `${year}-${month}-${day}`;
			},
			bindDateChange: function(e) {
				console.log(e)
				let year = e.target.value.substring(0, 4);
				this.date1 = year + '年' + e.target.value.substring(5) + '月';
				this.month=year + '-' + e.target.value.substring(5)
				this.getList();
			},
			getList() {
				let params = {
					type: 1,
					month: this.month
				}
				this.$get(this.$api.iLists, params,(res)=>{
					let {data}=res;
					console.log(data)
					if(data.code==1){
						
						this.list=data.data.data;
						this.total=data.data.total;
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.more-detail {
		background: white;
		min-height: 100vh;

		image {
			width: 60rpx;
			height: 60rpx;
			margin-right: 10rpx;
		}

		.sign {
			display: flex;
			align-items: center;
		}
		.bitmap {
			text-align: center;
		}
		.bitmap image{width: 400rpx;height: 480rpx;}
	}
</style>
